Web API Development with ASP.NET Core 8 by Xiaodi Yan

Web API Development with ASP.NET Core 8 by Xiaodi Yan

Author:Xiaodi Yan
Language: eng
Format: epub
Publisher: Packt Publishing Pvt. Ltd.
Published: 2024-03-02T00:00:00+00:00


Testing the happy path and the sad path

So far, we have written some tests to cover the happy path. However, we should also test the sad path. In testing, the terms happy path and sad path are used to describe different scenarios or test cases:

Happy path: A happy path refers to the ideal or expected scenario where the code unit being tested performs as intended. The input data is valid, and the code unit produces the expected output. Happy path tests are designed to validate the typical or desired behavior of the code unit. These tests ensure that the code works as expected without any errors or exceptions when the input data is valid. For example, in the GetInvoiceAsync(Guid id) method, the happy path is that the invoice with the specified ID exists in the database, and the method returns the invoice.

Sad path: A sad path, also known as the unhappy path, refers to the scenario where the code unit encounters an error or exception. The input data may be invalid, or the dependencies may not work as expected. Sad path tests are designed to validate whether the code unit can handle errors or exceptions gracefully. For example, in the GetInvoiceAsync(Guid id) method, the sad path is that the invoice with the specified ID does not exist in the database, and the method returns the 404 Not Found error.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.